#!/bin/bash

TRUNK=`pwd`
BRANCH=$TRUNK/$1
. `dirname $0`/svnmerge-setup.sh
# sets up PWD_IS_TRUNK and TRUNK_IS_MODIFIED

if test -z "$PWD_IS_TRUNK"
then
    echo Please execute this in trunk directory
    exit 1
fi
        
if test -z "$1"
then
    echo "Usage: $0 [branch path]"
    echo ""
    echo "  e.g. $0 ../branches/release1"
    exit 1
fi

if test -z "$TRUNK_IS_MODIFIED"
then
    echo MERGE branch CHANGES:
    echo " $BRANCH"
    echo INTO trunk:
    echo " $TRUNK"
    echo CTRL-C to abort, Enter to proceed.
    read junk

    svn update && svnmerge merge -b -s -S $BRANCH
    if test -n "`svn status $TRUNK | egrep -v '^\?'`"
    then
        echo To commit this merge, execute:
        echo " svn commit -F svnmerge-commit-message.txt && rm svnmerge-commit-message.txt"
    else
        echo "No changes it seems"
    fi
else
    printf "\n$TRUNK_IS_MODIFIED\n"
    echo TRUNK seems modified. Pls commit changes.
fi
